package com.sanji.sjmallmodule.account;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanji.sjmallapp.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by fhm on 2017/1/11.
 * 交易记录adapter
 */
public class BusinessDetailAdapter extends BaseAdapter {
    private List<BusinessDetailBean> mData;
    private Context mContex;

    public BusinessDetailAdapter(Context mContex, List<BusinessDetailBean> list) {
        this.mContex = mContex;
        this.mData = list;
    }

    public void notifyAdapter(List<BusinessDetailBean> mData) {
        this.mData = mData;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vHolder = null;
        if (view == null) {
            view = LayoutInflater.from(mContex).inflate(R.layout.adapter_business_detail_item, null);
            vHolder = new ViewHolder(view);
            view.setTag(vHolder);
        } else {
            vHolder = (ViewHolder) view.getTag();
        }
        BusinessDetailBean bean = mData.get(i);
        vHolder.businessAccount.setText(bean.getBusinessAccount() + "");
        vHolder.businessBuyChannel.setText(bean.getBusinessChannel());
        vHolder.businessBuyTime.setText(bean.getBusinessBuyTime());
        vHolder.businessNumber.setText(bean.getBusinessNumber());
        if (bean.getBusinessState() == 0) {
            vHolder.businessStateImg.setImageResource(R.mipmap.business_success);
        } else if (bean.getBusinessState() == 1) {
            vHolder.businessStateImg.setImageResource(R.mipmap.business_going);
        } else {
            vHolder.businessStateImg.setImageResource(R.mipmap.business_fail);
        }
        return view;
    }


    static class ViewHolder {
        @BindView(R.id.business_number)
        TextView businessNumber;
        @BindView(R.id.business_buy_time)
        TextView businessBuyTime;
        @BindView(R.id.business_buy_channel)
        TextView businessBuyChannel;
        @BindView(R.id.business_account)
        TextView businessAccount;
        @BindView(R.id.business_state_img)
        ImageView businessStateImg;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
